package com.aya.transaction.service.excpetion;

import com.aya.transaction.service.BlogSimpleTransactionService;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
@Service
public class DuplicateKeyService {
    @Resource
    BlogSimpleTransactionService blogSimpleTransactionService;
    /**
     * 事物1，事物2成功
     */
    @Transactional
    public void insertDuplicateKey(String id, String content, String id2, String content2) {
        blogSimpleTransactionService.insertRequired(id, content);
        try {
            blogSimpleTransactionService.insertRequired(id2, content2);
        } catch (DuplicateKeyException e) {
            e.printStackTrace();
        }
    }
}
